package com.gem.holder;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadFactory;

/**
 * Author: Xhy
 * CreateTime: 2022-10-15 11:54
 */
public class ThreadLocalFactory {
    private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();
    public static void put(String key, Object value){

        Map<String, Object> map = existAndCreate();
        map.put(key, value);
    }

    private static Map existAndCreate(){
        Map<String, Object> map = threadLocal.get();
        if(map==null) map = new HashMap<>();
        threadLocal.set(map);
        return map;
    }


    public static Object get(String key){
        Map map = existAndCreate();
        return map.get(key);
    }

    public static void remove() {
        threadLocal.remove();
    }


}
